/**
 * Copyright (c) 2011 - 2012 National Library of Medicine
 *
 * Contact: tomasz.adamusiak@nih.gov
 * 
 * This file is part of LOwlINC
 * 
 * LOwlINC is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version.
 * 
 * LOwlINC is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along
 * with LOwlINC. If not, see <http://www.gnu.org/licenses/>.
 */
package gov.nih.nlm.lowlinc.bean;

import gov.nih.nlm.lowlinc.accessionwrapper.LOINCTermID;
import gov.nih.nlm.lowlinc.owlapi.LowlincException;

import org.apache.log4j.Logger;

/**
 * @author Tomasz Adamusiak
 * 
 */
public class LOINCTerm {

	private static final Logger log = Logger.getLogger(LOINCTerm.class);

	private String LOINC_NUM;
	private String COMPONENT;
	private String PROPERTY;
	private String TIME_ASPCT;
	private String SYSTEM;
	private String SCALE_TYP;
	private String METHOD_TYP;
	private String RELAT_NMS;
	private String CLASS;
	private String SOURCE;
	private String DT_LAST_CH;
	private String CHNG_TYPE;
	private String COMMENTS;
	private String ANSWERLIST;
	private String STATUS;
	private String MAP_TO;
	private String SCOPE;
	private String CONSUMER_NAME;
	private String IPCC_UNITS;
	private String REFERENCE;
	private String EXACT_CMP_SY;
	private String MOLAR_MASS;
	private String CLASSTYPE;
	private String FORMULA;
	private String SPECIES;
	private String EXMPL_ANSWERS;
	private String ACSSYM;
	private String BASE_NAME;
	private String FINAL;
	private String NAACCR_ID;
	private String CODE_TABLE;
	private String SETROOT;
	private String PANELELEMENTS;
	private String SURVEY_QUEST_TEXT;
	private String SURVEY_QUEST_SRC;
	private String UNITSREQUIRED;
	private String SUBMITTED_UNITS;
	private String RELATEDNAMES2;
	private String SHORTNAME;
	private String ORDER_OBS;
	private String CDISC_COMMON_TESTS;
	private String HL7_FIELD_SUBFIELD_ID;
	private String EXTERNAL_COPYRIGHT_NOTICE;
	private String EXAMPLE_UNITS;
	private String INPC_PERCENTAGE;
	private String LONG_COMMON_NAME;
	private String HL7_V2_DATATYPE;
	private String HL7_V3_DATATYPE;
	private String CURATED_RANGE_AND_UNITS;
	private String DOCUMENT_SECTION;
	private String DEFINITION_DESCRIPTION_HELP;
	private String EXAMPLE_UCUM_UNITS;
	private String EXAMPLE_SI_UCUM_UNITS;
	private String STATUS_REASON;
	private String STATUS_TEXT;
	private String CHANGE_REASON_PUBLIC;
	private String COMMON_TEST_RANK;

	public String getLOINC_NUM() {
		return LOINC_NUM;
	}

	public LOINCTermID getTermID() throws LowlincException {
		return new LOINCTermID(getLOINC_NUM());
	}

	public String getLabel() {
		// <Analyte/component>:<kind of property of observation or
		// measurement>:<time aspect>:<system (sample)>:<scale>:<method>
		return getLOINC_NUM() + ":" + getCOMPONENT() + ":" + getPROPERTY()
				+ ":" + getTIME_ASPCT() + ":" + getSYSTEM() + ":"
				+ getSCALE_TYP() + ":" + getMETHOD_TYP();
	}

	public Boolean isActive() {
		if (getSTATUS().equals("ACTIVE")) {
			return true;
		} else {
			return false;
		}
	}

	public void setLOINC_NUM(String lOINC_NUM) {
		LOINC_NUM = lOINC_NUM;
	}

	public String getCOMPONENT() {
		return COMPONENT;
	}

	public void setCOMPONENT(String cOMPONENT) {
		COMPONENT = cOMPONENT;
	}

	public String getPROPERTY() {
		return PROPERTY;
	}

	public void setPROPERTY(String pROPERTY) {
		PROPERTY = pROPERTY;
	}

	public String getTIME_ASPCT() {
		return TIME_ASPCT;
	}

	public void setTIME_ASPCT(String tIME_ASPCT) {
		TIME_ASPCT = tIME_ASPCT;
	}

	public String getSYSTEM() {
		return SYSTEM;
	}

	public void setSYSTEM(String sYSTEM) {
		SYSTEM = sYSTEM;
	}

	public String getSCALE_TYP() {
		return SCALE_TYP;
	}

	public void setSCALE_TYP(String sCALE_TYP) {
		SCALE_TYP = sCALE_TYP;
	}

	public String getMETHOD_TYP() {
		return METHOD_TYP;
	}

	public void setMETHOD_TYP(String mETHOD_TYP) {
		METHOD_TYP = mETHOD_TYP;
	}

	public String getRELAT_NMS() {
		return RELAT_NMS;
	}

	public void setRELAT_NMS(String rELAT_NMS) {
		RELAT_NMS = rELAT_NMS;
	}

	public String getCLASS() {
		return CLASS;
	}

	public void setCLASS(String cLASS) {
		CLASS = cLASS;
	}

	public String getSOURCE() {
		return SOURCE;
	}

	public void setSOURCE(String sOURCE) {
		SOURCE = sOURCE;
	}

	public String getDT_LAST_CH() {
		return DT_LAST_CH;
	}

	public void setDT_LAST_CH(String dT_LAST_CH) {
		DT_LAST_CH = dT_LAST_CH;
	}

	public String getCHNG_TYPE() {
		return CHNG_TYPE;
	}

	public void setCHNG_TYPE(String cHNG_TYPE) {
		CHNG_TYPE = cHNG_TYPE;
	}

	public String getCOMMENTS() {
		return COMMENTS;
	}

	public void setCOMMENTS(String cOMMENTS) {
		COMMENTS = cOMMENTS;
	}

	public String getANSWERLIST() {
		return ANSWERLIST;
	}

	public void setANSWERLIST(String aNSWERLIST) {
		ANSWERLIST = aNSWERLIST;
	}

	public String getSTATUS() {
		return STATUS;
	}

	public void setSTATUS(String sTATUS) {
		STATUS = sTATUS;
	}

	public LOINCTermID getMAP_TO() throws LowlincException {
		if (MAP_TO.equals("")) {
			return null;
		}
		return new LOINCTermID(MAP_TO);
	}

	public void setMAP_TO(String mAP_TO) {
		MAP_TO = mAP_TO;
	}

	public String getSCOPE() {
		return SCOPE;
	}

	public void setSCOPE(String sCOPE) {
		SCOPE = sCOPE;
	}

	public String getCONSUMER_NAME() {
		return CONSUMER_NAME;
	}

	public void setCONSUMER_NAME(String cONSUMER_NAME) {
		CONSUMER_NAME = cONSUMER_NAME;
	}

	public String getIPCC_UNITS() {
		return IPCC_UNITS;
	}

	public void setIPCC_UNITS(String iPCC_UNITS) {
		IPCC_UNITS = iPCC_UNITS;
	}

	public String getREFERENCE() {
		return REFERENCE;
	}

	public void setREFERENCE(String rEFERENCE) {
		REFERENCE = rEFERENCE;
	}

	public String getEXACT_CMP_SY() {
		return EXACT_CMP_SY;
	}

	public void setEXACT_CMP_SY(String eXACT_CMP_SY) {
		EXACT_CMP_SY = eXACT_CMP_SY;
	}

	public String getMOLAR_MASS() {
		return MOLAR_MASS;
	}

	public void setMOLAR_MASS(String mOLAR_MASS) {
		MOLAR_MASS = mOLAR_MASS;
	}

	public String getCLASSTYPE() {
		return CLASSTYPE;
	}

	public void setCLASSTYPE(String cLASSTYPE) {
		CLASSTYPE = cLASSTYPE;
	}

	public String getFORMULA() {
		return FORMULA;
	}

	public void setFORMULA(String fORMULA) {
		FORMULA = fORMULA;
	}

	public String getSPECIES() {
		return SPECIES;
	}

	public void setSPECIES(String sPECIES) {
		SPECIES = sPECIES;
	}

	public String getEXMPL_ANSWERS() {
		return EXMPL_ANSWERS;
	}

	public void setEXMPL_ANSWERS(String eXMPL_ANSWERS) {
		EXMPL_ANSWERS = eXMPL_ANSWERS;
	}

	public String getACSSYM() {
		return ACSSYM;
	}

	public void setACSSYM(String aCSSYM) {
		ACSSYM = aCSSYM;
	}

	public String getBASE_NAME() {
		return BASE_NAME;
	}

	public void setBASE_NAME(String bASE_NAME) {
		BASE_NAME = bASE_NAME;
	}

	public String getFINAL() {
		return FINAL;
	}

	public void setFINAL(String fINAL) {
		FINAL = fINAL;
	}

	public String getNAACCR_ID() {
		return NAACCR_ID;
	}

	public void setNAACCR_ID(String nAACCR_ID) {
		NAACCR_ID = nAACCR_ID;
	}

	public String getCODE_TABLE() {
		return CODE_TABLE;
	}

	public void setCODE_TABLE(String cODE_TABLE) {
		CODE_TABLE = cODE_TABLE;
	}

	public String getSETROOT() {
		return SETROOT;
	}

	public void setSETROOT(String sETROOT) {
		SETROOT = sETROOT;
	}

	public String getPANELELEMENTS() {
		return PANELELEMENTS;
	}

	public void setPANELELEMENTS(String pANELELEMENTS) {
		PANELELEMENTS = pANELELEMENTS;
	}

	public String getSURVEY_QUEST_TEXT() {
		return SURVEY_QUEST_TEXT;
	}

	public void setSURVEY_QUEST_TEXT(String sURVEY_QUEST_TEXT) {
		SURVEY_QUEST_TEXT = sURVEY_QUEST_TEXT;
	}

	public String getSURVEY_QUEST_SRC() {
		return SURVEY_QUEST_SRC;
	}

	public void setSURVEY_QUEST_SRC(String sURVEY_QUEST_SRC) {
		SURVEY_QUEST_SRC = sURVEY_QUEST_SRC;
	}

	public String getUNITSREQUIRED() {
		return UNITSREQUIRED;
	}

	public void setUNITSREQUIRED(String uNITSREQUIRED) {
		UNITSREQUIRED = uNITSREQUIRED;
	}

	public String getSUBMITTED_UNITS() {
		return SUBMITTED_UNITS;
	}

	public void setSUBMITTED_UNITS(String sUBMITTED_UNITS) {
		SUBMITTED_UNITS = sUBMITTED_UNITS;
	}

	public String getRELATEDNAMES2() {
		return RELATEDNAMES2;
	}

	public void setRELATEDNAMES2(String rELATEDNAMES2) {
		RELATEDNAMES2 = rELATEDNAMES2;
	}

	public String getSHORTNAME() {
		return SHORTNAME;
	}

	public void setSHORTNAME(String sHORTNAME) {
		SHORTNAME = sHORTNAME;
	}

	public String getORDER_OBS() {
		return ORDER_OBS;
	}

	public void setORDER_OBS(String oRDER_OBS) {
		ORDER_OBS = oRDER_OBS;
	}

	public String getCDISC_COMMON_TESTS() {
		return CDISC_COMMON_TESTS;
	}

	public void setCDISC_COMMON_TESTS(String cDISC_COMMON_TESTS) {
		CDISC_COMMON_TESTS = cDISC_COMMON_TESTS;
	}

	public String getHL7_FIELD_SUBFIELD_ID() {
		return HL7_FIELD_SUBFIELD_ID;
	}

	public void setHL7_FIELD_SUBFIELD_ID(String hL7_FIELD_SUBFIELD_ID) {
		HL7_FIELD_SUBFIELD_ID = hL7_FIELD_SUBFIELD_ID;
	}

	public String getEXTERNAL_COPYRIGHT_NOTICE() {
		return EXTERNAL_COPYRIGHT_NOTICE;
	}

	public void setEXTERNAL_COPYRIGHT_NOTICE(String eXTERNAL_COPYRIGHT_NOTICE) {
		EXTERNAL_COPYRIGHT_NOTICE = eXTERNAL_COPYRIGHT_NOTICE;
	}

	public String getEXAMPLE_UNITS() {
		return EXAMPLE_UNITS;
	}

	public void setEXAMPLE_UNITS(String eXAMPLE_UNITS) {
		EXAMPLE_UNITS = eXAMPLE_UNITS;
	}

	public String getINPC_PERCENTAGE() {
		return INPC_PERCENTAGE;
	}

	public void setINPC_PERCENTAGE(String iNPC_PERCENTAGE) {
		INPC_PERCENTAGE = iNPC_PERCENTAGE;
	}

	public String getLONG_COMMON_NAME() {
		return LONG_COMMON_NAME;
	}

	public void setLONG_COMMON_NAME(String lONG_COMMON_NAME) {
		LONG_COMMON_NAME = lONG_COMMON_NAME;
	}

	public String getHL7_V2_DATATYPE() {
		return HL7_V2_DATATYPE;
	}

	public void setHL7_V2_DATATYPE(String hL7_V2_DATATYPE) {
		HL7_V2_DATATYPE = hL7_V2_DATATYPE;
	}

	public String getHL7_V3_DATATYPE() {
		return HL7_V3_DATATYPE;
	}

	public void setHL7_V3_DATATYPE(String hL7_V3_DATATYPE) {
		HL7_V3_DATATYPE = hL7_V3_DATATYPE;
	}

	public String getCURATED_RANGE_AND_UNITS() {
		return CURATED_RANGE_AND_UNITS;
	}

	public void setCURATED_RANGE_AND_UNITS(String cURATED_RANGE_AND_UNITS) {
		CURATED_RANGE_AND_UNITS = cURATED_RANGE_AND_UNITS;
	}

	public String getDOCUMENT_SECTION() {
		return DOCUMENT_SECTION;
	}

	public void setDOCUMENT_SECTION(String dOCUMENT_SECTION) {
		DOCUMENT_SECTION = dOCUMENT_SECTION;
	}

	public String getDEFINITION_DESCRIPTION_HELP() {
		return DEFINITION_DESCRIPTION_HELP;
	}

	public void setDEFINITION_DESCRIPTION_HELP(
			String dEFINITION_DESCRIPTION_HELP) {
		DEFINITION_DESCRIPTION_HELP = dEFINITION_DESCRIPTION_HELP;
	}

	public String getEXAMPLE_UCUM_UNITS() {
		return EXAMPLE_UCUM_UNITS;
	}

	public void setEXAMPLE_UCUM_UNITS(String eXAMPLE_UCUM_UNITS) {
		EXAMPLE_UCUM_UNITS = eXAMPLE_UCUM_UNITS;
	}

	public String getEXAMPLE_SI_UCUM_UNITS() {
		return EXAMPLE_SI_UCUM_UNITS;
	}

	public void setEXAMPLE_SI_UCUM_UNITS(String eXAMPLE_SI_UCUM_UNITS) {
		EXAMPLE_SI_UCUM_UNITS = eXAMPLE_SI_UCUM_UNITS;
	}

	public String getSTATUS_REASON() {
		return STATUS_REASON;
	}

	public void setSTATUS_REASON(String sTATUS_REASON) {
		STATUS_REASON = sTATUS_REASON;
	}

	public String getSTATUS_TEXT() {
		return STATUS_TEXT;
	}

	public void setSTATUS_TEXT(String sTATUS_TEXT) {
		STATUS_TEXT = sTATUS_TEXT;
	}

	public String getCHANGE_REASON_PUBLIC() {
		return CHANGE_REASON_PUBLIC;
	}

	public void setCHANGE_REASON_PUBLIC(String cHANGE_REASON_PUBLIC) {
		CHANGE_REASON_PUBLIC = cHANGE_REASON_PUBLIC;
	}

	public String getCOMMON_TEST_RANK() {
		return COMMON_TEST_RANK;
	}

	public void setCOMMON_TEST_RANK(String cOMMON_TEST_RANK) {
		COMMON_TEST_RANK = cOMMON_TEST_RANK;
	}

	public String getComponentProper() {
		return getCOMPONENT().split("\\^")[0].split("/")[0];
	}

	public String getChallenge() {
		String[] parts = getCOMPONENT().split("\\^");
		if (parts.length > 1) {
			return parts[1];
		} else {
			return "";
		}
	}

	public String getAdjustment() {
		String[] parts = getCOMPONENT().split("\\^");
		if (parts.length > 2) {
			return parts[2];
		} else {
			return "";
		}
	}

	public String getIndex() {
		String[] parts = getCOMPONENT().split("\\^");
		if (parts.length > 3) {
			return parts[3];
		} else {
			return "";
		}
	}

	public String getSystemProper() {
		return getSYSTEM().split("\\^")[0];
	}

	public String getSuperSystem() {
		String[] parts = getSYSTEM().split("\\^");
		if (parts.length > 1) {
			return parts[1];
		} else {
			return "";
		}
	}

	@Override
	public String toString() {
		return "LOINC Term [" + getLabel() + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ (LOINC_NUM == null ? 0 : LOINC_NUM.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		LOINCTerm other = (LOINCTerm) obj;
		if (LOINC_NUM == null) {
			if (other.LOINC_NUM != null) {
				return false;
			}
		} else if (!LOINC_NUM.equals(other.LOINC_NUM)) {
			return false;
		}
		return true;
	}

}
